#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020/9/3 15:10
# @Author : 吴敬超
# explain:
import pandas as pd
import threading
import numpy as np
import netCDF4 as nc
import datetime
import csv
import time as ti
import glob
import multiprocessing

file_path_wrf = 'D:/nc2json/wrf_2020070700_need.nc'
file_path_roms = 'D:/nc2json/roms_2020070700_need.nc'

file_obj_roms = nc.Dataset(file_path_roms)
file_obj_wrf = nc.Dataset(file_path_wrf)

# z_t = file_obj.variables['z_t'][:]
OLR = file_obj_wrf.variables['OLR'][:]
print OLR[0][0][0]


ocean_time = file_obj_roms.variables['ocean_time']
wrfTime = file_obj_wrf.variables['Time']

ocean_times = nc.num2date(ocean_time[:], ocean_time.units)
wrfTimes = nc.num2date(wrfTime[:], wrfTime.units)

print ocean_times[1].strftime("%Y-%m-%d_%H:%M:%S")
print wrfTimes[1].strftime("%Y-%m-%d_%H:%M:%S")

roms_lon_u = file_obj_roms.variables['lon_u'][:]
roms_lon_v = file_obj_roms.variables['lon_v'][:]
roms_lat_u = file_obj_roms.variables['lat_u'][:]


# 经纬   Longitude and latitude
def rangflag(Lon=0, lat=0, Lonstart=39, Lonstop=178, latstart=-16, latstop=62):
    if (Lonstart <= Lon <= Lonstop) and (latstart <= lat <= latstop):
        return True

    return False


# 经纬   Longitude and latitude
def Longituderangflag(x, xstart=39, xstop=178):
    if xstart <= x <= xstop:
        return True

    return False


# 经纬   Longitude and latitude
def latituderangflag(y, ystart=-16, ystop=62):
    if ystart <= y <= ystop:
        return True

    return False


#
#
romsu = file_obj_roms.variables['u'][:]

print romsu.shape
print len(romsu)
print len(romsu[5][0])

print len(romsu[6][0][2])


print roms_lon_u[200][200]
#
# for utime in range(0, len(romsu)):
#
#     for ueta_u in range(0, len(romsu[utime][0])):
#
#         for uxi_u in range(0, len(romsu[utime][0][ueta_u])):
#             print "000000000"
#
#             # roms_lon_u[ueta_u][uxi_u]
#
#             rangflag(roms_lon_u[ueta_u][uxi_u],roms_lat_u[ueta_u][uxi_u])


#
#
# temp = file_obj_roms.variables['temp'][:]
#
#
# templat=temp[0][0][0][1430]
# print templat
#
#
#
# romsulat=romsu[0][0][0][1430]
# print romsulat
#
